<template>
  <div class="productListWait">
    <div class="container">

      <!-- <createTop firstMenu="订单管理" secondMenu="生产单" title="入库"></createTop> -->
      <el-button
        size="small"
        plain
        type="primary"
        class="back"
        @click="back">返回</el-button>
      <!-- 第一个表格 -->
        <div class="first-title">
          <!-- <div class="left big-wrod">等待配料</div> -->
          <div class="right">
            <div class="right-top">
              <div><span class="big">生产单号: </span>{{row.sc_order}}</div>
              <div><span class="big">销售员: </span>{{row.sell_username}}</div>
              <div><span class="big">交货日期: </span>{{row.date}}</div>
            <!-- </div> -->
            <!-- <div class="right-bottom"> -->
              <div><span class="big">订单号: </span>{{row.dd_order}}</div>
            </div>
          </div>
        </div>
      <el-card class="first">

        <div slot="header" class="card-title">
          <span>待入库清单</span>
        </div>
        <!-- <tableList :tableData="listData" @add='add' @del='del'></tableList> -->
           <div class="productListWait-table-wrap">
              <el-table
                :data="tableData"
                style="width: 100%"
                :fit="true"
                :stripe="true"
                size="mini"
                :border="true"
                align="center">

                <el-table-column
                  prop="goods_number"
                  label="商品编号"
                  min-width="100"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="goods_name"
                  label="商品名称"
                  min-width="130"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="class_name"
                  label="分类"
                  min-width="130"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="goods_model"
                  label="型号"
                  min-width="120"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="material_unit"
                  label="单位"
                  min-width="120"
                  align="center">
                </el-table-column>

                <el-table-column
                  prop="count"
                  label="生产数量"
                  min-width="120"
                  align="center">
                </el-table-column>
                
                <el-table-column 
                label="入库数量"
                min-width="180"
                align="center">
                  <template slot-scope="scope">
                    <el-input 
                    v-model="scope.row.outCount" 
                    @blur="changeOutCount(scope)"
                    placeholder="输入入库数量"></el-input>
                  </template>
                </el-table-column>

                <el-table-column 
                label="备注"
                min-width="180"
                align="center">
                  <template slot-scope="scope">
                    <el-input 
                    v-model="scope.row.tableRemark" 
                    placeholder="填写备注"></el-input>
                  </template>
                </el-table-column>
              </el-table>
              <deleteConfirm v-if="showMask" @closeDelete="closeDelete" @deleteConfirm="deleteConfirm"></deleteConfirm>
            </div>
      </el-card>

      <el-card shadow="always">
        <div slot="header" class="card-title">
          <span>出库信息</span>
        </div>
        <div class="content">
          <div class="content-title">制单人</div>
            <el-input :style="{'width':'350px'}" disabled v-model="doName" placeholder="读取账号"></el-input>

          <div class="content-title">入库日期 <span class="red-icon">※</span></div>
            <el-date-picker
              v-model="date"
              type="date"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd">
            </el-date-picker>

          <div class="content-title">入库类型 </div>
            <el-input :style="{'width':'350px'}" disabled v-model="leixing" placeholder="输入适当的备注方便管理"></el-input>

          <div class="content-title">经办人 <span class="red-icon">※</span> </div>
            <el-input :style="{'width':'350px'}" v-model="doname" placeholder="输入经办人姓名"></el-input>

          <div class="content-title">入库单号 </div>
            <el-input :style="{'width':'350px'}" disabled v-model="rukuid" placeholder="自动填充"></el-input>

          <div class="content-title">入库备注  </div>
            <el-input :style="{'width':'350px'}" v-model="remark" type="textarea" :rows="5" resize="none" placeholder="输入适当的备注方便管理"></el-input>
        </div>
      </el-card>
        <el-button
        class="confirm"
        size="mini"
        type="primary"
        @click="confirm">入库</el-button>

      <el-dialog v-if="inStockDialog" title="提示" center width="400px" :visible="true" @close="close">
        <div :style="{'textAlign':'center'}">商品数量{{number}}</div>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="inStockConfirm">确 定</el-button>
          </span>
      </el-dialog>


      <!-- <childTable :id="id" v-show="showChild" @confirm="addTable" @close="closeChild"></childTable> -->
    </div>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import createTop from '@/components/createTop.vue';
import saveBtn from '@/components/saveBtn.vue';
import ajaxResquest from '@/api/apiRequest';
import childTable from '@/tables/order/productListWaitChild.vue';
@Component({
  components: {
    createTop,
    saveBtn,
    // childTable
  }
})
export default class ProductListWait extends Vue {
  createRes!: ajaxResquest;
  infoRes!: ajaxResquest;
  inStockRes!: ajaxResquest;

  row: any = [];

  tableData: any = [];

  outCount: string = '';
  tableRemark: string = '';
  showMask: boolean = false;
  leixing: string = '';
  doname: string = '';
  rukuid: string = '';
  remark: string = '';
  doName: string = '';
  date: any = '';
  showChild: boolean = false;
  $router!: any;
  id: any = '';
  inStockDialog: boolean = false;
  number: number = 0

  created() {
    // console.log(this.id);
  }
  mounted() {
    // this.row = temp;
    this.infoRes = new ajaxResquest('/order/productionsInfo');
    this.createRes = new ajaxResquest('/order/productionsIn');
    this.id = this.$route.query.id
    // this.getInfo();
    console.log(this.$route.query);
    this.tableData = this.$route.query.row
    this.inStockRes = new ajaxResquest('/order/getGoodsNumber');


  }
  getInfo() {
    this.infoRes.getFunction({ orderId: this.id }).then((res: any) => {
      let temp: any[] = [res.data.data.types.goods];
      this.row = temp;
    });
  }
  add(val: any) {
    console.log(val);
    this.showChild = true;
  }
  del(index: number, val: any) {
    // console.log(val);
    console.log(index);
    this.tableData.splice(index, 1);
  }
  closeChild() {
    this.showChild = false;
  }
  addTable(val: any) {
    let temp = val;
    let tempData: any[] = [];
    temp.map((i: any) => {
      i._models_id.map((j: any) => {
        let count!: number;
        let name!: string;
        let fId!: string;
        i.formats_info.forEach((e: any) => {
          if (e.format_id === j) {
            count = e.material_all_count;
            name = e.format_name;
            fId = e.format_id;
          }
        });
        let data = {
          materials_id: i.materials_id,
          material_name: i.material_name,
          material_number: i.material_number,
          material_unit: i.material_unit,
          need_count: i.need_count,
          format_name: name,
          format_id: fId,
          material_all_count: count,
          tableRemark: '',
          outCount: 0
        };
        tempData.push(data);
      });
    });
    this.tableData = [this.tableData, ...tempData];
    console.log(this.tableData);
    this.showChild = false;
  }
  changeOutCount(scope: any) {
    console.log(scope.row);
    if (scope.row.outCount > scope.row.material_all_count) {
      console.log('数量超了');
    }
  }
  confirm(): void {
    console.log(this.id);

    this.inStockRes.getFunction({ orderId: this.id }).then((res: any) => {
      if (res.data.code === 1) {
        console.log(res.data.data);
        this.inStockDialog = true;
        this.number = res.data.data.types;
      }

    })
  }
  close() {
    this.inStockDialog = false;
  }
  inStockConfirm() {
    let data = {
      doName: this.doname,
      data: this.date,
      remarks: this.remark,
      state:'生产入库',
      orderId:this.id
    }
    this.createRes.getFunction()
  }
  back() {
    this.$to('productList')
  }

}
</script>
<style lang="less">
.productListWait {
  height: 100%;
  padding: 15px;
  display: flex;
  flex-direction: column;
  // z-index: 101;
  box-sizing: border-box;
  overflow-y: auto;
  position: relative;
  .top-card {
    // padding: 10px;
    box-sizing: border-box;
    margin-bottom: 15px;
  }
  .el-card {
    overflow-y: auto;
  }
  .content {
    display: flex;
    flex-direction: column;
    font-size: 16px;
    background-color: #fff;
    border-radius: 4px;
    .content-title {
      height: 40px;
      margin-top: 20px;
      line-height: 2;
      text-align: left;
    }
    .short-input {
      width: 100%;
      width: 240px;
      margin-right: 10px;
    }
    .el-upload-list__item {
      width: 350px;
    }
    .el-textarea {
      margin-bottom: 30px;
    }
  }
  .card-title {
    text-align: left;
    font-weight: 600;
  }
  .first {
    margin-bottom: 15px;
    text-align: left;
    // display: flex;
    // flex-direction: row;
  }
  .first-title {
    display: flex;
    margin-bottom: 20px;
  }
  .left {
    margin-right: 40px;
    // float: left;
    // height: 100%;
  }
  .big-wrod {
    font-size: 24px;
    color: red;
  }
  .right {
    font-size: 14px;
    div {
      text-align: left;
      min-width: 140px;
      margin-right: 10px;
    }
    .big {
      font-weight: 600;
    }
  }
  .right-top {
    display: flex;
    margin-bottom: 10px;
  }
  .red {
    color: red;
  }
  .confirm {
    margin-top: 15px;
  }
  .back {
    position: absolute;
    right: 15px;
    top: 15px;
  }
}
</style>
